<?php 
class M_satuan extends CI_Model{
	
	function getlist($filter,$offset,$limit){
		$this->db->limit($limit);
		$this->db->offset($offset);
		$this->db->where('satuan_aktif','Y');
		if(!empty($filter)){
			$this->db->where("lower(satuan_nama) LIKE '%".addslashes(strtolower($filter))."%'");
		}
		$query = $this->db->get('m_satuan');
		$total = $this->db->select('*')->from('m_satuan')->where('satuan_aktif','Y')->count_all_results();
		$arr = array();
		foreach($query->result() as $q){
			$arr[] = $q; 
		}
		$final = array('results' => $arr,
					   'total'  => $total);
		return json_encode($final);
	}
	function save($data){
		$this->db->insert('m_satuan',$data);
		return 1;
	}
	function update($id,$data){
		$this->db->where('satuan_id',$id);
		$this->db->update('m_satuan',$data);
		return 1;
	}
	function delete($id,$data){
		$this->db->where('satuan_id',$id);
		$this->db->update('m_satuan',$data);
		return 1;
	}
}